<template>
	<view class="quxiaoorder">
		<headertop title="取消订单" str1="oridei" :back1="back1"></headertop>
		<view class="quxiaoorder_back">

		</view>
		<view class="centerbox">
			<view class="topordernum">
				<image src="https://39gongli.oss-cn-beijing.aliyuncs.com/static/微信图片_20250429143332.png" mode="">
				</image>
				<view class="numtext">
					订单号：{{contentobj.order_no}}
				</view>
			</view>
			<view class="infobox" v-for="item in  orderfilearr" :key="item.id">
				<image :src="item.image" class="leftimg" mode=""></image>
				<view class="righttext">
					<view class="t1">
						<span>{{item.title}}</span>
					</view>
					<view class="t2">
						{{item.detail}}
					</view>
					<view class="t3">
						<view class="num">
							x{{item.num}}
						</view>
						<view class="jiage">
							￥{{item.price}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="shenqly">
			<view class="centerbox1">
				<view class="title">
					申请理由
				</view>
				<view class="textsbox">
					<textarea v-model="content" placeholder="请输入取消理由" />
				</view>
			</view>
		</view>
		<view class="fixedbox">
			<view class="btn" @click="quxiaodingdan">
				确认提交
			</view>
		</view>
		<up-popup :show="show" mode="center">
			<view class="popucenter">
				<image src="https://39gongli.oss-cn-beijing.aliyuncs.com/static/Group@2x.png" class="popucenterimg"
					mode=""></image>
				<view class="title">
					申请成功
				</view>
				<view class="text">
					已提交审核耐心等待~
				</view>
				<view class="btn" @click="back">
					确认
				</view>
			</view>
		</up-popup>
	</view>
</template>

<script setup>
	import headertop from '@/components/header.vue'
	import {
		onPageScroll,
		onLoad
	} from "@dcloudio/uni-app";
	import {
		orderfile,
		changstatus
	} from '@/api/commodity.js'
	import {
		ref
	} from 'vue'
	const back1 = ref('')
	const content = ref('')
	const show = ref(false)
	const orderfilearr = ref([])
	const contentobj = ref({})
	onPageScroll((e) => {
		if (e.scrollTop > 100) {
			back1.value = '#84BD78'
		} else {
			back1.value = ''
		}
	})
	onLoad((opt) => {
		init(opt.id)
	})
	async function quxiaodingdan() {
		if (!content.value) {
			uni.showToast({
				title: '申请理由不能为空',
				icon: 'none'
			})
			return
		}
		uni.showModal({
			title: '提示', // 标题（可选）
			content: '确定要取消吗？', // 内容（可选）
			confirmText: '确定', // 确认按钮文字（可选，默认“确定”）
			cancelText: '取消', // 取消按钮文字（可选，默认“取消”）
			success: (res) => {
				if (res.confirm) {
					// 执行确定后的逻辑
					qx1()
				} else if (res.cancel) {
					console.log('用户点击了取消');
					// 执行取消后的逻辑
				}
			},
			fail: (err) => {
				console.error('弹窗调用失败', err);
			}
		});
	}

	async function qx1() {
		const res = await changstatus({
			id: contentobj.value.id,
			memo: content.value,
			status: 1
		})
		if (res.code == 0) {
			uni.showToast({
				title: res.msg,
				icon: 'none'
			})
			return
		}
		if (res.data.code == 1) {
			show.value = true

		} else {
			uni.showToast({
				title: res.msg,
				icon: 'none'
			})
		}
	}

	function back() {
		uni.navigateBack()
	}
	async function init(id) {

		var res = await orderfile({
			id
		})

		if (res.data.code == 1) {
			contentobj.value = res.data.data.order
			orderfilearr.value = res.data.data.goods
		}
	}
</script>
<style lang="scss">
	page {
		background: #F7F8FA;
	}

	::v-deep .u-popup__content {
		background-color: rgba(255, 0, 0, 0) !important;
	}

	.popucenter {
		width: 592rpx;
		height: 596rpx;
		background: linear-gradient(180deg, #F4FFF5 0%, #FFFFFF 31%);
		border-radius: 28rpx 28rpx 28rpx 28rpx;
		overflow: hidden;
		display: flex;
		flex-direction: column;
		align-items: center;

		.popucenterimg {
			width: 355.92rpx;
			height: 315.24rpx;
			margin-top: 22rpx;
		}

		.title {
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 36rpx;
			color: #1D2129;
			margin-bottom: 24rpx;
		}

		.text {
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 24rpx;
			color: #4E5969;
		}

		.btn {
			width: 422rpx;
			height: 64rpx;
			background: #7EBC79;
			border-radius: 8rpx 8rpx 8rpx 8rpx;
			text-align: center;
			line-height: 64rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 28rpx;
			color: #FFFFFF;
			margin-top: 22rpx;
		}

	}

	.quxiaoorder {
		width: 100%;
		overflow: hidden;
		position: relative;

		.fixedbox {
			width: 100%;
			overflow: hidden;
			height: 184rpx;
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			position: fixed;
			bottom: 0%;
			box-shadow: 0rpx -4rpx 4rpx 0rpx rgba(0, 0, 0, 0.08);
			border-radius: 0rpx 0rpx 0rpx 0rpx;

			.btn {
				width: 686rpx;
				height: 88rpx;
				background: #7EBC79;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				text-align: center;
				line-height: 88rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 30rpx;
				color: #FFFFFF;
				text-align: center;
				line-height: 88rpx;
				margin: auto;
				margin-top: 22rpx;
			}
		}

		&_back {
			position: absolute;
			z-index: -1;
			width: 100%;
			height: 530rpx;
			background: linear-gradient(180deg, #84BD78 0%, rgba(132, 189, 120, 0) 100%);
			border-radius: 0rpx 0rpx 0rpx 0rpx;
		}

		.shenqly {
			width: 686rpx;
			height: 206rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 0rpx 14rpx 0rpx rgba(0, 0, 0, 0.18);
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			margin: 28rpx auto;

			.centerbox1 {
				width: 646rpx;
				margin: auto;
				overflow: hidden;

				.title {
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 28rpx;
					color: #1D2129;
					margin-top: 20rpx;
				}

				.textsbox {
					width: 646rpx;
					margin-top: 14rpx;

					textarea {
						font-size: 24rpx;
						height: 100rpx;
					}
				}
			}
		}

		.centerbox {
			width: 686rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 0rpx 14rpx 0rpx rgba(0, 0, 0, 0.18);
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			overflow: hidden;
			margin: auto;
			margin-top: 186rpx;

			.yajinbox {
				width: 630rpx;
				margin: auto;
				height: 90rpx;
				display: flex;
				align-items: center;
				margin-top: 28rpx;
				font-weight: 400;
				font-size: 24rpx;
				color: #86909C;
				border-top: 1rpx solid #C9CDD4;
			}

			.infobox {
				width: 630rpx;
				margin: auto;
				margin-top: 36rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 32rpx;

				.leftimg {
					width: 162rpx;
					height: 144rpx;
					border-radius: 20rpx 20rpx 20rpx 20rpx;

				}

				.righttext {
					width: 412rpx;
					overflow: hidden;

					.t2 {
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 26rpx;
						color: #868686;
						margin-top: 16rpx;
						white-space: nowrap;
						/* 防止文本换行 */
						overflow: hidden;
						/* 隐藏超出容器的部分 */
						text-overflow: ellipsis;
						/* 超出部分显示为省略号 */
					}

					.t3 {
						width: 100%;
						display: flex;
						align-items: center;
						justify-content: space-between;
						margin-top: 22rpx;

						.num {
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							font-size: 26rpx;
							color: #868686;
						}

						.jiage {
							font-family: PingFang SC, PingFang SC;
							font-weight: bold;
							font-size: 36rpx;
							color: #7EBC79;
						}
					}

					.t1 {
						display: flex;
						align-items: center;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 32rpx;
						color: #1D2129;

						.gu {
							width: 48rpx;
							height: 32rpx;
							background: #7EBC79;
							border-radius: 4rpx 16rpx 4rpx 16rpx;
							text-align: center;
							line-height: 32rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 500;
							font-size: 24rpx;
							color: #FFFFFF;
							margin-right: 8rpx;
						}
					}
				}
			}

			.topordernum {
				width: 630rpx;
				margin: auto;
				display: flex;
				align-items: center;
				margin-top: 30rpx;

				image {
					width: 24rpx;
					height: 27rpx;
				}

				.numtext {
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 28rpx;
					color: #1D2129;
					margin-left: 12rpx;
				}
			}
		}
	}
</style>